package com.bfsuol.common.dao.hibernate;

import org.springframework.stereotype.Repository;

import com.bfsuol.common.Constants;
import com.bfsuol.common.dao.LoginDAO;
import com.bfsuolframework.security.entity.BaseUser;
import com.bfsuolframework.core.dao.HibernateDAOSupport;
import com.bfsuolframework.core.dao.support.HqlParameter;
@Repository
public class LoginDAOImpl extends HibernateDAOSupport<BaseUser> implements LoginDAO{

	/**
	 * 根据用户名 密码 获取用户
	 * @param loginName
	 * @param password
	 * @return
	 */
	public BaseUser getBaseUserByLogin(String loginName,String password) {

		return getByHql("from BaseUser bu where bu.status= :status and bu.loginName = :loginName and bu.password = :password  ",HqlParameter.newInstance("loginName", loginName).addParameter("password", password).addParameter("status", Constants.STATUS_VALID));
	}

	/**
	 * 根据邮箱重置密码
	 * @param loginName
	 * @param email
	 * @return
	 */
	public BaseUser getBaseUserByEmail(String loginName, String email) {
		return getByHql("from BaseUser bu where  bu.loginName = :loginName and bu.email = :email",HqlParameter.newInstance("loginName", loginName).addParameter("email", email));
	}

}
